home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 19 / madtrb11.zip / PWRR.INC < prev    next >
Text File  |  1986-01-21  |  1KB  |  46 lines

  1. Function PwrR(x,y : real): real;
  2. {Written by Paul F. Hultquist.  Found in May 1985 PC Tech Journl             }
  3. {PwrR finds X (real) to the power Y (real) using logarithms and exponentials.}
  4. {If Y is an integer PwrI is faster.  The function eliminates the undefined   }
  5. {cases, and the case where the result is complex.                            }
  6.  
  7. Begin
  8.   if x > 0 then
  9.     PwrR := exp(y*ln(x))
  10.   else
  11.     if x < 0 then
  12.       begin
  13.         writeln('x < 0.  Halt.');
  14.         Halt;
  15.       end
  16.     else
  17.       if (x = 0) and (y = 0) then
  18.         begin
  19.           writeln('0 to the 0 power.  Halt.');
  20.           Halt;
  21.         end
  22.       else
  23.         if (x = 0) and (y < 0) then
  24.           begin
  25.             writeln('0 to a negative power.  Halt.');
  26.             Halt;
  27.           end
  28.         else
  29.           PwrR := 0.0;
  30. End;  {PwrR}function Mpwr(num : real; expon : integer): real;
  31. Var
  32.   M : real;
  33.   I : integer;
  34. begin
  35.   M := num;
  36.   for I := 2 to expon do
  37.     num := num * M;
  38.   Mpwr := num;
  39. end; {Rpwr}
  40. function Rpwr(num : real; expon : integer): real;
  41. begin
  42.   if expon = 0 then Rpwr :=1
  43.   else
  44.   Rpwr := num * Rpwr(num, expon - 1);
  45. end; {Rpwr}
  46.